home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9000 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: crchh327.rich.bnr.ca!jobell
  2. From: jobell@bnr.ca (Bret Bieghler)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: sizeof class
  5. Date: 27 Feb 1996 21:04:44 GMT
  6. Organization: Bell-Northern Research Ltd.
  7. Message-ID: <4gvrlc$2l6@crchh327.rich.bnr.ca>
  8. References: <Pine.SOL.3.91.960226185535.3663A-100000@turing.uncg.edu> <4gvi3s$53a@horn.wyoming.com>
  9. NNTP-Posting-Host: crchh524.rich.bnr.ca
  10.  
  11. In article <4gvi3s$53a@horn.wyoming.com>,
  12. Dave Cromley <dcromley@wyoming.com> wrote:
  13. >Bin . Lee wrote:
  14. >>class TestClass {};
  15. >>sizeof TestClass is 1 for BC++, is this normal ? 
  16. >>Where dose computer store this pointer ? 
  17. >
  18. >Yes, it is 1, isn't it? 
  19. >I would have thought the size would be 0.
  20. >There is no pointer.
  21. >
  22. >class TestClass2 { int i1; };
  23. >has a sizeof 2--the size of the int.
  24. >struct TestStruct { };
  25. >has a sizeof 1--I would have expected 0.
  26. >
  27. >  Dave C.
  28. >
  29.  
  30. C++ forces the size of objects to be of nozero
  31. size because each object must have a distinct
  32. address. (Bruce Eckel)
  33.  
  34. Consider:
  35.  
  36.     TestClass aTestClassArray[100];
  37.  
  38. if they are all of zero size, how do you index
  39. into the array?
  40.  
  41. Therefore, the C++ compiler inserts a dummy.
  42.  
  43. (See Bruce Eckel, "Thinking in C++", page 543).
  44.  
  45. Joe
  46. -- 
  47. Joseph A. Bell (NOT Bret Bieghler) jobell@bnr.ca
  48. Northern Telecom / Bell-Northern Research
  49. "What?  Evacuate now, in our moment of triumph?  Surely you overestimate their chances."
  50.